package method

import (
	"server/biz"
	"server/service"
)

func PlaceOrder2(md *service.Meta) (interface{}, error) {
	var pkg_ids []int
	err := md.Get("pkgs").Unmarshal(&pkg_ids)
	if err != nil {
		return nil, service.NewError(400, err.Error())
	}
	if len(pkg_ids) == 0 {
		return nil, service.NewError(400, "请选择游戏")
	}
	platform := md.Get("platform").String()
	if platform == "" {
		return nil, service.NewError(400, "PLATFORM_EMPTY")
	}
	no := md.Get("no").String()
	sysv := md.Get("sysv").String()
	cp := md.Get("cap").Float64()
	if cp <= 0 {
		return nil, service.NewError(400, "CAP_INVALID")
	}
	user_id := biz.GetCookieUserId(md.Request)
	o := &biz.OrderRaw{
		UserId:   user_id,
		No:       no,
		Platform: platform,
		Sysv:     sysv,
		Cap:      cp,
	}
	biz.CreateOrder(o, pkg_ids)
	return o.No, nil
}
